package com.zzyl.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.zzyl.dto.FloorDto;
import com.zzyl.entity.Floor;
import com.zzyl.mapper.FloorMapper;
import com.zzyl.service.BedService;
import com.zzyl.service.FloorService;
import com.zzyl.service.RoomService;
import com.zzyl.vo.FloorVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


@Service

public class FloorServiceImpl implements FloorService {


    @Autowired
    RoomService roomService;

    @Autowired
    BedService bedService;

    @Autowired
    private FloorMapper floorMapper;


    //添加楼层
    @Override
    public void addFloor(FloorDto floorDto) {
        Floor floor = new Floor();
        BeanUtils.copyProperties(floorDto, floor);
        floor.setCreateTime(LocalDateTime.now());
        floor.setCreateBy(1l);
        floorMapper.addFloor(floor);
    }

    //查询楼层
    @Override
    public FloorVo getFloor(Long id) {
        return floorMapper.getFloor(id);
    }

    //获取所有楼层
    @Override
    public List<FloorVo> getAllFloors() {
        List<FloorVo> floorVos = floorMapper.getAllFloors();
        return floorVos.stream().map(floorVo -> {
            FloorVo floorVo1 = new FloorVo();
            BeanUtils.copyProperties(floorVo, floorVo1);
            return floorVo1;
        }).collect(Collectors.toList());

    }

    //删除楼层
    @Override
    public void deleteFloos(Long id) {
        floorMapper.deleteFloos(id);
    }

    //修改楼层
    @Override
    public void updateFloor(FloorDto floorDto) {
        Floor floor = BeanUtil.toBean(floorDto, Floor.class);
        floor.setUpdateBy(1L);
        floor.setUpdateTime(LocalDateTime.now());
        floorMapper.updateFloor(floor);
    }


    @Override
    public List<FloorVo> getAllWithRoomAndBed() {
        return floorMapper.selectAllRoomAndBed();
    }

    @Override
    public List<FloorVo> selectAllByNur() {
        return floorMapper.selectAllByNur();
    }


}

